<?php
/**
 * Class UsersController
 *
 * @author: Monica 
 * 
 */
 
class UsersController extends BaseController{
	
	
	public function bind(){
		
		$users_ids = $this->UsersSqlDAO-> queryAll("userID");
		$users = array();
		if (!empty($_POST['user']) || !empty($users_ids)) {
			$users = array_merge((array)$_POST['user'], (array)$users_ids);
			$users = array_filter(array_unique($users));
	
		}
		return $users;
	
	}
	
	
	/**
	 * 
	 * Copy from upload.php authentication
	 */
	public function authenticate(){
		            
//		if (isset($_SESSION['auth']) && ($_SESSION['permissions'] == 'A' || $_SESSION['permissions'] == 'U')) {
//			
//			$proxy_name = '';
//			$proxy_port = '';
//			$proxy_username = '';
//			$proxy_password = '';
//			
//			if (isset($_SESSION['connection']) && ($_SESSION['connection'] == "autodetect" || $_SESSION['connection'] == "url")) {
//				if(!empty($_POST['proxystr'])) {
//					$proxy_arr = explode (';', $_POST['proxystr']);
//					foreach ($proxy_arr as $proxy_str) {
//						if (stripos(trim($proxy_str), 'PROXY') === 0) {
//							$proxy_str = trim(substr ($proxy_str, 6));
//							$proxy_name = parse_url($proxy_str, PHP_URL_HOST);
//							$proxy_port = parse_url($proxy_str, PHP_URL_PORT);
//							$proxy_username = parse_url($proxy_str, PHP_URL_USER);
//							$proxy_password = parse_url($proxy_str, PHP_URL_PASS);
//							break;
//						}
//					}
//				} else {
//					if(isset($_SESSION['proxy_name'])) $proxy_name = $_SESSION['proxy_name'];
//					if(isset($_SESSION['proxy_port'])) $proxy_port = $_SESSION['proxy_port'];
//					if(isset($_SESSION['proxy_username'])) $proxy_username = $_SESSION['proxy_username'];
//					if(isset($_SESSION['proxy_password'])) $proxy_password = $_SESSION['proxy_password'];
//				}
//			}
//			
//			session_write_close();
//		}
		
		
	}

	/**
	 * Get Domain object by primry key
	 *
	 * @param String $id primary key
	 * @Return Users 
	 */
	public function load($id){
		$this->set("usersList",$this->_model->load($id));
	}

	/**
	 * Get all records from table
	 */
	public function queryAll(){
		
		$this->set("usersList",$this->_model->queryAll());
	}
	
	/**
	 * Get all records from table ordered by field
	 * @Param $orderColumn column name
	 */
	public function queryAllOrderBy($orderColumn){
		
		$this->set("usersList",$this->_model->queryAll($orderColumn));
	}
	
	/**
 	 * Delete record from table
 	 * @param user primary key
 	 */
	public function delete($userID){}
	
	/**
 	 * Insert record to table
 	 *
 	 * @param Users user
 	 */
	public function insert($user){}
	
	/**
 	 * Update record in table
 	 *
 	 * @param Users user
 	 */
	public function update($user){
		
		return $this->_model->update($user);
	}

	/**
	 * Delete all rows
	 */
	public function clean(){
		return $this->_model->clean();
	}

	public function queryByUserName($value){
		$this->set("user",$this->_model->queryByUSerName($value));
		
	}

	public function queryByPassword($value){
		$this->set("user",$this->_model->queryByPassword($value));
	}

	public function queryByPermissions($value){
		$this->set("user",$this->_model->queryByPermissions($value));
		
		
	}


	public function deleteByUsername($value){
		return $this->_model->deleteByUsername($value);
	}

	public function deleteByPassword($value){
		return $this->_model->deleteByPassword($value);
	}

	public function deleteByPermissions($value){
		return $this->_model->deleteByPermissions($value);
	}


}
?>